﻿Imports System.Reflection
Imports System.ComponentModel.DataAnnotations

<AttributeUsage(AttributeTargets.Property)>
Public Class ColumnDefinitionAttribute
    Inherits Attribute

    Public Property Column As ColumnAttribute

    ''' <summary>
    ''' NULL許容
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property IsNullable As Boolean = False

    ''' <summary>
    ''' サイズ
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Size As String

    ''' <summary>
    ''' 列タイプ
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' ex.1  nvarchar({0})}
    ''' ex.2  int
    ''' {0}  ColumnSizeが代入されます。
    ''' </remarks>
    Public Property ColumnType As String

    ''' <summary>
    ''' 定義コマンドテキスト
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' ex.1  nvarchar(100) NOT NULL
    ''' ex.2  int NULL
    ''' ex.3  int IDENTITY (1, 1) NOT NULL
    ''' 列名は含みません。
    ''' </remarks>
    Public Property CommandText As String

    Public ReadOnly Property ColumnFullText As String
        Get
            Return String.Format("{0} {1}", Me.Column.ColumnName, Me.CommandText)
        End Get
    End Property


    ''' <summary>
    ''' 列の並び順
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Index As Integer

    Private _isStaticLength As Boolean? = False
    ''' <summary>
    ''' 固定長かどうかを示します。
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>プロパティの型がStringの場合にのみ有効</remarks>
    Public Property IsStaticLength() As Boolean?
        Get
            If Me.Column.PropertyInfo Is Nothing Then Return Nothing
            If Me.Column.PropertyInfo.GetType.FullName <> GetType(String).FullName Then Return Nothing
            Return _isStaticLength
        End Get
        Set(ByVal value As Boolean?)
            _isStaticLength = value
        End Set
    End Property

    ''' <summary>
    ''' 親の表示属性
    ''' </summary>
    Friend Property ParentDisplayAttribute As DisplayAttribute
    Friend Property DisplayAttribute As DisplayAttribute
End Class
